//
//  HDFindPWVC.swift
//  HuaDaoPeifu
//
//  Created by ZERO on 2018/6/14.
//  Copyright © 2018年 paiyipai. All rights reserved.
//

import UIKit

class HDFindPWVC: UIViewController {

    var  accountType :HDUserType?
    var timer = Timer()
    var timeCount = 60
    var countdownTimer: Timer?

    
    @IBOutlet weak var phoneView: UIView!
    
    @IBOutlet weak var codeView: UIView!
    
    @IBOutlet weak var passwordView: UIView!
    
    @IBOutlet weak var passwordView2: UIView!
    
    @IBOutlet weak var phoneTF: UITextField!
    
    @IBOutlet weak var codeTF: UITextField!
    
    @IBOutlet weak var codeBtn: UIButton!
    
    @IBOutlet weak var pwTF1: UITextField!
    
    @IBOutlet weak var pwTF2: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        title = "找回密码"
        setUI()

    }

    
    func setUI() {
        
        phoneView.layer.borderWidth = 1
        phoneView.layer.cornerRadius = 3
        phoneView.layer.borderColor = UIColor(hex: 0xdbdbdb).cgColor
        
        codeView.layer.borderWidth = 1
        codeView.layer.cornerRadius = 3
        codeView.layer.borderColor = UIColor(hex: 0xdbdbdb).cgColor
        
        passwordView.layer.borderWidth = 1
        passwordView.layer.cornerRadius = 3
        passwordView.layer.borderColor = UIColor(hex: 0xdbdbdb).cgColor
        
        passwordView2.layer.borderWidth = 1
        passwordView2.layer.cornerRadius = 3
        passwordView2.layer.borderColor = UIColor(hex: 0xdbdbdb).cgColor
    }
    
    func startTimer() {
        codeBtn.isEnabled = false
        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(beginCountDown), userInfo: nil, repeats: true)
    }
    
    func beginCountDown() {
        //print(timeCount)
        timeCount -= 1
        
        codeBtn.setTitle("(\(timeCount)秒)", for: .disabled)
        if timeCount == 0 {
            codeBtn.isEnabled = true
            timer.invalidate()
            timeCount = 60
        }
    }


    //倒计时
    var remainingSeconds: Int = 0 {
        willSet {
            codeBtn.setTitle("(\(newValue)秒)", for: UIControlState())
            if newValue <= 0 {
                codeBtn.setTitle("重新获取", for: UIControlState())
                isCounting = false
            }
        }
    }
    var isCounting = false {
        willSet {
            if newValue {
                countdownTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
                remainingSeconds = 60
                codeBtn.setTitleColor(UIColor(hex:0x999999), for: UIControlState())
            } else {
                countdownTimer?.invalidate()
                countdownTimer = nil
                codeBtn.setTitleColor(ConstantColor.appThemeColor, for: UIControlState())
            }
            codeBtn.isEnabled = !newValue
        }
    }
    func updateTime(_ timer: Timer) {
        remainingSeconds -= 1
    }

    // 获取验证码
    @IBAction func codeAction(_ sender: UIButton) {
        
    }
    
    @IBAction func loginAction(_ sender: UIButton) {
         navigationController?.popViewController(animated: true)
        
    }
    
    @IBAction func registAction(_ sender: UIButton) {
        
        let registVC = HDRegistVC()
        registVC.accountType = accountType
        navigationController?.pushViewController(registVC, animated: true)
    }
    
    // 确认
    @IBAction func confirmAction(_ sender: UIButton) {
        
    }
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
